﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Innovation
{
    public class Transform
    {
        Vector3 position = Vector3.Zero;
        Matrix rotation = Matrix.Identity;
        Vector3 scale = Vector3.One;

        public event EventHandler PositionChanged;
        public event EventHandler RotationChanged;
        public event EventHandler ScaleChanged;

        public Vector3 Position
        {
            get { return position; }
            set { position = value; if (PositionChanged != null) PositionChanged(this, new EventArgs()); }
        }

        public Matrix Rotation
        {
            get { return rotation; }
            set { rotation = value; }
        }

        public Vector3 EulerRotation
        {
            get { return MathUtil.MatrixToVector3(rotation); }
            set { rotation = MathUtil.Vector3ToMatrix(value); if (RotationChanged != null) RotationChanged(this, new EventArgs()); }
        }

        public Vector3 Scale
        {
            get { return scale; }
            set { scale = value; if (ScaleChanged != null) ScaleChanged(this, new EventArgs()); }
        }

        public Transform()
        {
        }

        public Transform(Vector3 Position, Vector3 Rotation)
        {
            this.Position = Position;
            this.EulerRotation = Rotation;
        }

        public Transform(Vector3 Position, Matrix Rotation)
        {
            this.Position = Position;
            this.Rotation = Rotation;
        }

        public Transform(Vector3 Position, Vector3 Rotation, Vector3 Scale)
        {
            this.Position = Position;
            this.EulerRotation = Rotation;
            this.Scale = Scale;
        }

        public Transform(Vector3 Position, Matrix Rotation, Vector3 Scale)
        {
            this.Position = Position;
            this.Rotation = Rotation;
            this.Scale = Scale;
        }

        public Transform Combine(Transform Transform)
        {
            Transform newT = new Transform();

            newT.Position += Transform.Position;
            newT.Rotation *= Transform.Rotation;
            newT.Scale *= Transform.Scale;

            return newT;
        }
    }
}
